﻿using Microsoft.AspNetCore.Mvc;

namespace NET6Demo.WebApi.Controllers
{
    /// <summary>
    /// 特性路由解读
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    public class AttributeRouteController : ControllerBase
    {
        private readonly ILogger<AttributeRouteController> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger"></param>
        public AttributeRouteController(ILogger<AttributeRouteController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 获取信息
        /// </summary>
        /// <returns></returns>
        [HttpGet()]
        public User GetUser()
        {
            return new()
            {
                Id = 123,
                Name = "Richard---来自于1.0版本的数据",
                Age = 28
            };
        }

        /// <summary>
        /// 通过Id获取信息
        /// </summary>
        /// <returns></returns> 
        [HttpGet()]
        [Route("{id:int}")]
        public User GetUserById(int id)
        {
            return new()
            {
                Id = 123,
                Name = "Richard---来自于1.0版本的数据",
                Age = 28
            };
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet()]
        [Route("{pageIndex:int}/{pageSize:int}/{keyword?}")]
        public object GetPageUser(int pageIndex, int pageSize, string? keyword)
        {
            return new
            {
                pageIndex = pageIndex,
                pageSize = pageSize,
                keyword = keyword
            };
        }

        /// <summary>
        /// 新增信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost()]
        public int AddUser(User user)
        {
            return 1;
        }

        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut()]
        public int UpdateUser(User user)
        {
            return 1;
        }

        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpDelete()]
        public int DeleteUser(int userId)
        {
            return 1;
        }


    }
}
